<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">编辑活动</div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3  am-u-lg-2 am-form-label form-require"> 选择商品</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button type="button"
                                                class="j-selectUser upload-file333 am-btn am-btn-secondary am-radius">
                                            <i class="am-icon-cloud-upload"></i> 选择商品
                                        </button>
                                        <div class="uploader-list am-cf">

                                                <div class="file-item">
                                                    <a href="<?= $model['goods_image'] ?>" title="点击查看大图" target="_blank">
                                                        <img  class="manba" src="<?= $model['goods_image'] ?>">
                                                    </a>
                                                    <input type="hidden" class="goods_id" name="manba[goods_id]"
                                                           value="<?= $model['goods_id'] ?>">
                                                    <input type="hidden" class="goods_image" name="manba[goods_image]"
                                                           value="<?= $model['goods_image'] ?>">
                                                    <i class="iconfont icon-shanchu file-item-delete"></i>
                                                </div>

                                        </div>
                                        <div class="am-block">
                                            <small>选择后不可更改</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 所属门店 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="manba[shop_id]"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm', placeholder:'请选择', maxHeight: 400}"
                                            required>
                                        <option value=""></option>
                                        <?php if (isset($shopList) && !$shopList->isEmpty()):
                                            foreach ($shopList as $item): ?>
                                                <option value="<?= $item['shop_id'] ?>"
                                                    <?= $model['shop_id'] == $item['shop_id'] ? 'selected' : '' ?>>
                                                    <?= $item['shop_name'] ?></option>
                                            <?php endforeach; endif; ?>
                                    </select>
                                    <div class="help-block">
                                        <small>请选择店员所属的门店，用于核销订单</small>
                                    </div>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">活动标题 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="manba[title]" value="<?= $model['title'] ?>"
                                           placeholder="请输入活动标题" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">活动简介</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="manba[content]" value="<?= $model['content'] ?>"
                                           placeholder="请输入活动标题" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">活动图片 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div class="am-form-file">
                                        <div class="am-form-file">
                                            <button type="button"
                                                    class="upload-file trtrt am-btn am-btn-secondary am-radius">
                                                <i class="am-icon-cloud-upload"></i> 选择图片
                                            </button>
                                            <div class="uploader-list am-cf">
                                            <?php foreach ($model['bei_img'] as $key => $item): ?>

                                                <div class="file-item">
                                                    <a href="<?= $item['goods_image'] ?>" title="点击查看大图" target="_blank">
                                                        <img src="<?= $item['goods_image'] ?>">
                                                    </a>
                                                    <input type="hidden" name="manba[bei_img][]"
                                                           value="<?= $item['goods_id']  ?>">
                                                    <i class="iconfont icon-shanchu file-item-delete"></i>
                                                </div>

                                            <?php endforeach; ?>
                                            </div>
                                        </div>
                                        <div class="help-block am-margin-top-sm">
                                            <small>尺寸750x750像素以上，大小2M以下 (可拖拽图片调整显示顺序 )</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">活动人数</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="manba[num]"
                                           placeholder="请输入活动人数" value="<?= $model['num'] ?>" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require"> 手机号 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="manba[phone]"
                                           placeholder="请输入手机号" value="<?= $model['phone'] ?>" required>
                                </div>
                            </div>


                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">活动选择状态 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="manba[deduct_stock_type]" value="10" data-am-ucheck
                                            <?= $model['deduct_stock_type'] == 10 ? 'checked' : '' ?> >
                                        只能报名
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="manba[deduct_stock_type]" value="20" data-am-ucheck
                                            <?= $model['deduct_stock_type'] == 20 ? 'checked' : '' ?> >
                                        购买和报名
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 图片文件列表模板 -->
<script id="tpl-user-item" type="text/template">
    {{ each $data }}
    <div class="file-item">
        <a href="{{ $value.image }}" title="{{ $value.goods_name }} (ID:{{ $value.goods_id }})" target="_blank">
            <img src="{{ $value.image }}">
        </a>
        <input type="hidden" name="manba[goods_id]" value="{{ $value.goods_id }}">
        <input type="hidden" name="manba[goods_image]" value="{{ $value.image }}">
    </div>
    {{ /each }}
</script>
</script>
// <!-- 图片文件列表模板 -->
{{include file="layouts/_template/tpl_file_item" /}}

<!-- 文件库弹窗 -->
{{include file="layouts/_template/file_library" /}}

<script src="assets/common/js/vue.min.js"></script>
<script src="assets/common/js/ddsort.js"></script>
<script src="assets/common/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="assets/common/plugins/umeditor/umeditor.min.js"></script>
<script src="assets/store/js/goods.spec.js?v=<?= $version ?>"></script>
<script src="assets/store/js/select.data.js?v=<?= $version ?>"></script>
<script>
    $(function () {

        $('.trtrt').click(function () {
            // 选择图片
            $('.upload-file').selectImages({
                name: 'manba[bei_img][]'
                , multiple: true
            });
        })
        // 选择图片
        $('.upload-file1333').selectImages({
            name: 'shop[goods_id]'
        });

        // 图片列表拖动
        $('.uploader-list').DDSort({
            target: '.file-item',
            delay: 100, // 延时处理，默认为 50 ms，防止手抖点击 A 链接无效
            floatStyle: {
                'border': '1px solid #ccc',
                'background-color': '#fff'
            }
        });
        // 选择用户
        $('.j-selectUser').click(function () {
            var $userList = $('.user-list');
            $.selectData({
                title: '选择用户',
                uri: 'goods/lists',
                dataIndex: 'goods_id',
                done: function (data) {
                    console.log(data)

                    $('.manba').attr('src',data[0]['goods_image'])
                    $('.goods_id').val(data[0]['goods_id'])
                    $('.goods_image').val(data[0]['goods_image'])
                    var goods = [data[0]];
                    $userList.html(template('tpl-user-item', goods));
                }
            });
        });

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });

</script>
